/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SnpDbHandling;

import SnpDbEntities.User;
import SnpDbEntities.UserPermissions;

/**
 *
 * @author Łukasz 'byku' Guzik
 */
public class ModeratorPermissionsPolicy extends UserPermissionsPolicy {

    protected ModeratorPermissionsPolicy(User askingUser)
    {
	super(askingUser);
    }

    @Override
    public boolean canAddUser(User userToAdd)
    {
	return false;
    }

    @Override
    public boolean canDeleteUser(User userToDelete)
    {
	return false;
    }

    @Override
    public boolean canDisEnableUser(User userToDisEnable)
    {
	if(userToDisEnable.getPermissions() == UserPermissions.NORMAL_USER)
	    return true;

	if(userToDisEnable.getPermissions() == UserPermissions.MODERATOR
		&& askingUser.getId() == userToDisEnable.getId())
	    return true;

	return false;
    }

    @Override
    public boolean canUpdateUser(User userToUpdate, User newUserData)
    {
	if(userToUpdate.getPermissions() != newUserData.getPermissions())
	    return false;

	if(userToUpdate.getPermissions() == UserPermissions.SUPER_ADMIN
		|| userToUpdate.getPermissions() == UserPermissions.ADMIN
		|| newUserData.getPermissions() == UserPermissions.SUPER_ADMIN
		|| newUserData.getPermissions() == UserPermissions.ADMIN)
	    return false;

	if(userToUpdate.getPermissions() == UserPermissions.MODERATOR
		&& askingUser.getId() != userToUpdate.getId())
	    return false;

	return true;
    }

    @Override
    public boolean canChangePublicCategories()
    {
	return false;
    }

    @Override
    public boolean canUpdatePublicSnippet()
    {
	return true;
    }
}
